package com.example.demo.controller;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.BoundValueOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Demo {
	@Value("${time}")
	private int time;
	@Resource
	private RedisTemplate<Object, Object> redis;
	@RequestMapping("/getDemo")
	public String getDemo(HttpServletRequest request){
		try{
			Map<String,Object> map=new HashMap<>();
			map.put("ok", "ok");
			map.put("1", 1);
			BoundValueOperations<Object, Object> r=redis.boundValueOps(map);
			r.set("value");
			System.out.println(r.get());
			redis.opsForValue().set("ok", map, time, TimeUnit.HOURS);	
			Object s=redis.opsForValue().get("ok");
			request.getSession().setAttribute("", "");
			System.out.println(s.toString());
		}catch(Exception e){
			System.out.println(e.getMessage());
		}
	return redis.opsForValue().get("ok").toString();
	}
}
